package com.zxw.设计模式.结构型.组合模式;

import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: util-cloud
 * @package: com.zxw.设计模式.结构型.组合模式
 * @className: Directory
 * @author: zhangxuewei
 * @description: TODO
 * @date: 2023/9/28 10:25
 * @version: 1.0
 */
public class Directory extends Entry {

    private String name;
    private List<Entry> directory = new ArrayList<>();

    // 构造方法注入名称
    public Directory(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public int getSize() {
        int size = 0;
        for (Entry e : directory) {
            size += e.getSize();
        }
        return size;
    }

    @Override
    public void printList(String prefix) {
        System.out.println(prefix + "/" + this);
        for (Entry entry : directory) {
            entry.printList(prefix + "/" + name);
        }
    }


    @Override
    public Entry add(Entry entry) {
        directory.add(entry);
        return this;
    }


}
